package com.scsystem.xysc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scsystem.xysc.pojo.ActionLog;
import com.scsystem.xysc.service.ActionLogService;
import com.scsystem.xysc.mapper.ActionLogMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author sky
* @description 针对表【action_log】的数据库操作Service实现
* @createDate 2023-10-09 20:08:20
*/
@Service
public class ActionLogServiceImpl extends ServiceImpl<ActionLogMapper, ActionLog>
    implements ActionLogService{
    @Resource
    private ActionLogMapper actionLogMapper;

    /**
     * 模糊查询日志信息
     *
     * @param condition 查询条件
     * @param page      页码
     * @param count     每页的条目数
     * @return 分页对象
     */
    @Override
    public Page<ActionLog> getLogPage(String condition, int page, int count) {

        if (condition == null) {
            return actionLogMapper.selectPage(new Page<>(page, count), null);
        }

        QueryWrapper<ActionLog> queryWrapper = new QueryWrapper<>();

        queryWrapper.like("log_id", "%" + condition + "%")
                .or().like("log_type", "%" + condition + "%")
                .or().like("action_id", "%" + condition + "%")
                .or().like("user_type", "%" + condition + "%")
                .or().like("action_time", "%" + condition + "%")
                .or().like("url", "%" + condition + "%")
                .or().like("operation_description", "%" + condition + "%")
                .or().like("message", "%" + condition + "%")
                .or().like("parameter",  "%" + condition + "%")
                .or().like("result", "%" + condition + "%")
                .or().like("IPAddr",  "%" + condition + "%")
                .or().like("time_consuming", "%" + condition + "%");

        return actionLogMapper.selectPage(new Page<>(page, count), queryWrapper);
    }
}




